package com.mdd.front.controller;

import com.mdd.common.core.AjaxResult;
import com.mdd.common.entity.user.User;
import com.mdd.common.entity.user.UserGoods;
import com.mdd.front.LikeFrontThreadLocal;
import com.mdd.front.service.IUserGoodsService;
import com.mdd.front.service.impl.UserGoodsServiceImpl;
import com.mdd.front.validate.shop.ShopProductSearchValidate;
import com.mdd.front.vo.shop.ShopProductListedVo;
import com.mdd.front.vo.user.UserGoodsListedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("api/usergoods")
@Api(tags = "用户关注商品管理")
public class UserGoodsController {
    @Resource
    IUserGoodsService userGoodsService;


    @GetMapping("/list")
    @ApiOperation(value="用户关注列表")
    public AjaxResult<List<UserGoodsListedVo>> list() {
        Integer userId = LikeFrontThreadLocal.getUserId();
        List<UserGoodsListedVo> list = userGoodsService.list(userId);
        return AjaxResult.success(list);
    }


    @PostMapping("/focus")
    @ApiOperation(value="关注")
    public AjaxResult<Object> focus(@RequestBody UserGoods userGoods) {
        Integer userId = LikeFrontThreadLocal.getUserId();
        userGoods.setUserId(userId);
        userGoodsService.focusGoods(userGoods);
        return AjaxResult.success();
    }

    @GetMapping("/cancellation")
    @ApiOperation(value="取消关注")
    public AjaxResult<Object> cancellationFocus(Integer goodsId) {
        Integer userId = LikeFrontThreadLocal.getUserId();
        userGoodsService.cancellationFocus(userId,goodsId);
        return AjaxResult.success();
    }


    @GetMapping("/isfocus")
    @ApiOperation(value="是否关注")
    public AjaxResult<Boolean> isFocus(Integer goodsId) {
        Integer userId = LikeFrontThreadLocal.getUserId();
        return AjaxResult.success(userGoodsService.isFocus(userId,goodsId));
    }


}
